<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app"></div>
</body>
<script src="js/vue.js"></script>
<script>

    /* 指令
        1. 定义全局指令
        2. 定义局部指令 
    */

    // 定义局部指令
    const FocusDirective = {
        focus: {
            mounted(el) {   // 生命周期钩子函数
                el.focus();
            }
        }
    };


    const app = Vue.createApp({
        data() {
            return {
                msg: 'mixin 混入指定属性',
            }
        },
        // 用于挂载局部指令
        directives: FocusDirective,
        template: `
          <div>
            <input placeholder="请输入" v-focus />
          </div>
        `,
    });


    // 定义全局指令
    app.directive('focus', {
        mounted(el) {
            el.focus();
        }
    });

    app.mount("#app");

</script>

</html>